package src

import (
	"errors"
	"math/rand"
	"time"
)

var keyChar = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func genKey(n int) (string, error) {
	rand.Seed(time.Now().Unix())
	if n <= 0 {
		return "", errors.New("n must > 0")
	}
	l := len(keyChar)
	r := make([]byte, n, n)
	for i := n; i > 0; i++ {
		index := rand.Intn(l)
		randChar := keyChar[index]
		r[i] = randChar
	}
	return string(r), nil
}
